package arraylist_imagenes;

import java.util.Random;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import javax.imageio.ImageIO;
import javax.swing.JPanel;

public class ClaPanel extends JPanel implements MouseListener{
	private static final int ANCHO = 42;
	private static final int ALTO = 38;
	private BufferedImage biSerieImagen;
	private Motor motor;

	public ClaPanel(Motor motor){
		this.motor = motor;
		this.setSize(600, 600);
		this.cargaSerie();
	}

	private void cargaSerie() {
		try{
			biSerieImagen = ImageIO.read(getClass().getClassLoader().getResource("globo.png"));
		}catch(Exception e){
			
		}
		
	}
	
	public void paintComponent(Graphics g){
		super.paintComponent(g);
		g.setColor(Color.white);
		g.fillRect(0, 0, 600, 600);
		
		dibujaExplociones(g);
	}

	private void dibujaExplociones(Graphics g) {
		
		if(motor.obtieneSerieDibujos().size() != 0){
			ArrayList aux = motor.obtieneSerieDibujos();
			for(int cont=0; cont<aux.size(); cont++){
				ClaSeries e = (ClaSeries) aux.get(cont);
				g.drawImage(biSerieImagen,e.posX,e.posY,e.posX+ANCHO, e.posY+ALTO, e.obtieneNumDibujo()*ANCHO, 0, e.obtieneNumDibujo()*ANCHO+ANCHO, ALTO, null);

			}
		}
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent me) {
		motor.obtieneSerieDibujos().add(new ClaSeries(me.getX(), me.getY(), motor));
		
	}



	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}
	
}
